package com.github.mustfun.mybatis.plugin.setting;

import com.intellij.ui.components.JBScrollPane;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import lombok.Getter;
import lombok.Setter;

import javax.swing.*;
import java.awt.*;

/**
 * @author dengzhiyuan
 * @version 1.0
 * @date 2018/6/15
 * @since 1.0
 */
@Setter
@Getter
public class TemplateEdit {
    private JPanel mainPanel;
    private JTextArea codeArea;
    private JBScrollPane scrollCodeAreaPane;

    {
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
        $$$setupUI$$$();
    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        mainPanel = new JPanel();
        mainPanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
        mainPanel.setPreferredSize(new Dimension(800, 1080));
        scrollCodeAreaPane = new JBScrollPane();
        Font scrollCodeAreaPaneFont = this.$$$getFont$$$("Microsoft JhengHei UI", -1, -1, scrollCodeAreaPane.getFont());
        if (scrollCodeAreaPaneFont != null) scrollCodeAreaPane.setFont(scrollCodeAreaPaneFont);
        mainPanel.add(scrollCodeAreaPane, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        codeArea = new JTextArea();
        Font codeAreaFont = this.$$$getFont$$$(null, -1, 16, codeArea.getFont());
        if (codeAreaFont != null) codeArea.setFont(codeAreaFont);
        scrollCodeAreaPane.setViewportView(codeArea);
    }

    /**
     * @noinspection ALL
     */
    private Font $$$getFont$$$(String fontName, int style, int size, Font currentFont) {
        if (currentFont == null) return null;
        String resultName;
        if (fontName == null) {
            resultName = currentFont.getName();
        } else {
            Font testFont = new Font(fontName, Font.PLAIN, 10);
            if (testFont.canDisplay('a') && testFont.canDisplay('1')) {
                resultName = fontName;
            } else {
                resultName = currentFont.getName();
            }
        }
        return new Font(resultName, style >= 0 ? style : currentFont.getStyle(), size >= 0 ? size : currentFont.getSize());
    }

    /**
     * @noinspection ALL
     */
    public JComponent $$$getRootComponent$$$() {
        return mainPanel;
    }
}
